Binding in getX

  • Steps

    What is binding

    When a route is removed from the Stack, all controllers, variables, and instances of objects related to it are removed from memory.

    The Binding class is a class that will decouple dependency injection, while "binding" routes to the state manager and dependency manager. This allows Get to know which screen is being displayed when a particular controller is used and to know where and how to dispose of it.

    you don't have to worry about memory management of your application anymore, Get will do it for you.

    How bindings work

    Bindings creates transitory factories, which are created the moment you click to go to another screen, and will be destroyed as soon as the screen-changing animation happens. This happens so fast that the analyzer will not even be able to register it. When you navigate to this screen again, a new temporary factory will be called

    Bindings Class

    
                         class HomeBinding implements Bindings {
                            @override
                            void dependencies() {
                              Get.lazyPut<HomeController>(() => HomeController());
                              Get.put<Service>(()=> Api());
                            }
                          }
    
                          class DetailsBinding implements Bindings {
                            @override
                            void dependencies() {
                              Get.lazyPut<DetailsController>(() => DetailsController());
                            }
                          }
    
                          

    Using named routes:

    
                          getPages: [
      GetPage(
        name: '/',
        page: () => HomeView(),
        binding: HomeBinding(),
      ),
      GetPage(
        name: '/details',
        page: () => DetailsView(),
        binding: DetailsBinding(),
      ),
    ];